<template>
  <div class="modern-container">
    <!-- 主内容区域 -->
    <div v-if="showFlag">
      <!-- 工具栏 -->
      
        <el-form :inline="true" :model="searchForm" class="modern-search-form">
          <div class="modern-search-panel">
          <div class="search-fields">
            
            <el-form-item class="search-item">
              <el-input
                prefix-icon="el-icon-document"
                v-model="searchForm.xiqukepuName"
                placeholder="科普名称"
                clearable
                class="modern-input"
              ></el-input>
            </el-form-item>

            <el-form-item class="search-item">
              <!-- <el-input
          prefix-icon="el-icon-document"
          v-model="searchForm.xiqukepuTypes"
          placeholder="知识类型"
          clearable
          class="modern-input"
        ></el-input> -->
              <el-select
                v-model="searchForm.xiqukepuTypes"
                placeholder="知识类型"
                class="modern-select"
              >
                <el-option label="全部类型" value=""></el-option>
                <el-option
                  v-for="(item, index) in xiqukepuTypesSelectSearch"
                  :key="index"
                  :label="item.indexName"
                  :value="item.codeIndex"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item class="search-item date-range">
              <el-date-picker
                v-model="searchForm.insertTimeStartSearch"
                type="datetime"
                placeholder="开始时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                class="modern-date"
              ></el-date-picker>
              <span class="date-separator">至</span>
              <el-date-picker
                v-model="searchForm.insertTimeEndSearch"
                type="datetime"
                placeholder="结束时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                class="modern-date"
              ></el-date-picker>
            </el-form-item>
            <el-button type="primary" class="modern-search-btn" @click="search">
              <i class="el-icon-search"></i>知识检索
            </el-button>
          </div>
        </div>
          <div class="action-buttons">
            <el-button-group class="action-group">
              <el-button
                v-if="isAuth('xiqukepu', '新增')"
                type="success"
                class="modern-action-btn"
                @click="addOrUpdateHandler()"
              >
                <i class="el-icon-plus"></i>新建知识
              </el-button>

              <el-button
                v-if="isAuth('xiqukepu', '删除')"
                :disabled="dataListSelections.length <= 0"
                type="danger"
                class="modern-action-btn"
                @click="deleteHandler()"
              >
                <i class="el-icon-delete"></i>批量删除
              </el-button>

              <el-button
                v-if="isAuth('xiqukepu', '报表')"
                type="warning"
                class="modern-action-btn"
                @click="chartDialog()"
              >
                <i class="el-icon-data-analysis"></i>知识分析
              </el-button>

              <el-button
                v-if="isAuth('xiqukepu', '导入导出')"
                type="info"
                class="modern-action-btn"
              >
                <i class="el-icon-upload"></i>导出典藏
              </el-button>
            </el-button-group>
          </div>
        </el-form>

              <!-- 数据表格 -->
      <div class="modern-search-panel">
        <div class="modern-table-container">
          <el-table
            :data="dataList"
            class="modern-data-table"
            v-loading="dataListLoading"
            @selection-change="selectionChangeHandler"
            style="width: 100%"
          >
            <el-table-column
              v-if="contents.tableSelection"
              type="selection"
              width="45"
              align="center"
            ></el-table-column>

            <!-- 知识卡片 -->
            <el-table-column
              prop="xiqukepuName"
              label="中医知识"
              min-width="240"
            >
              <template slot-scope="scope">
                <div class="modern-card">
                  <div class="card-image" v-if="scope.row.xiqukepuPhoto">
                    <img
                      :src="$base.url + scope.row.xiqukepuPhoto"
                      alt="中医知识图示"
                      @click="handleImagePreview(scope.row)"
                    />
                    <div class="card-badge">祖传秘方</div>
                  </div>
                  <div class="card-content">
                    <h3 class="card-title">
                      <i class="el-icon-notebook-2"></i>
                      {{ scope.row.xiqukepuName }}
                    </h3>
                    <div class="card-meta">
                      <!-- <el-tag type="warning" class="card-type">
                  {{ scope.row.xiqukepuValue }}
                </el-tag> -->
                      <span class="card-time">
                        <i class="el-icon-time"></i>
                        {{ scope.row.insertTime }}
                      </span>
                    </div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="xiqukepuName"
              label="知识类型"
              min-width="240"
            >
              <template slot-scope="scope">
                <div class="modern-card">
                  <div class="card-content">
                    <div class="card-meta">
                      <el-tag type="warning" class="card-type">
                        {{ scope.row.xiqukepuValue }}
                      </el-tag>
                    </div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <!-- 操作列 -->
            <el-table-column
              label="操作"
              width="180"
              fixed="right"
              align="center"
            >
              <template slot-scope="scope">
                <div class="table-actions">
                  <el-tooltip content="查看典籍" placement="top">
                    <el-button
                      type="text"
                      icon="el-icon-document"
                      @click="addOrUpdateHandler(scope.row.id, 'info')"
                      class="action-btn"
                    ></el-button>
                  </el-tooltip>

                  <el-tooltip content="修订内容" placement="top">
                    <el-button
                      type="text"
                      icon="el-icon-edit"
                      @click="addOrUpdateHandler(scope.row.id)"
                      class="action-btn"
                    ></el-button>
                  </el-tooltip>

                  <el-tooltip content="移出库藏" placement="top">
                    <el-button
                      type="text"
                      icon="el-icon-delete"
                      @click="deleteHandler(scope.row.id)"
                      class="action-btn danger"
                    ></el-button>
                  </el-tooltip>
                </div>
              </template>
            </el-table-column>
          </el-table>

          <!-- 分页 -->
          <div class="modern-pagination">
            <el-pagination
              background
              :page-sizes="[10, 20, 50, 100]"
              :page-size="Number(contents.pageEachNum)"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalPage"
              @size-change="sizeChangeHandle"
              @current-change="currentChangeHandle"
            ></el-pagination>
          </div>
        </div>
      </div>
      </div>

    
    <!-- 添加/修改页面  将父组件的search方法传递给子组件-->
    <add-or-update
      v-if="addOrUpdateFlag"
      :parent="this"
      ref="addOrUpdate"
    ></add-or-update>
    <!-- 知识图谱弹窗 -->
    <el-dialog
      title="中医知识图谱分析"
      :visible.sync="chartVisiable"
      width="90%"
      class="herbal-dialog"
      top="5vh"
    >
      <div class="herbal-chart-header">
        <el-date-picker
          v-model="echartsDate"
          type="year"
          placeholder="选择传承年份"
          value-format="yyyy"
          class="herbal-date-picker"
          prefix-icon="el-icon-herbal-calendar"
        ></el-date-picker>
        <el-button
          type="primary"
          class="herbal-analysis-btn"
          @click="chartDialog()"
        >
          <i class="el-icon-herbal-analysis"></i>
          生成图谱
        </el-button>
      </div>
      <div id="statistic" class="herbal-chart-container"></div>
    </el-dialog>

    <el-dialog title="打印" :visible.sync="printVisiable" width="500px">
      <el-form ref="printContent" :model="printFrom" label-width="auto">
        <el-form-item label="发件人">
          <div style="display: flex">
            <el-input v-model="printFrom.kuaidiFajianName" disabled></el-input>
            :
            <el-input
              v-model="printFrom.kuaidiFajianShoujihao"
              disabled
            ></el-input>
          </div>
        </el-form-item>
        <el-form-item label="发件人地址">
          <el-input v-model="printFrom.kuaidiFajianAddress" disabled></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="printContent()" icon="el-icon-printer" type="success"
          >打印</el-button
        >
        <el-button @click="printVisiable = false">关闭</el-button>
      </span>
    </el-dialog>

    <el-dialog title="统计报表" :visible.sync="chartVisiable" width="80%">
      <el-date-picker v-model="echartsDate" type="year" placeholder="选择年">
      </el-date-picker>
      <el-button @click="chartDialog()">查询</el-button>
      <div id="statistic" style="width: 100%; height: 600px"></div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="chartVisiable = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import AddOrUpdate from "./add-or-update";
import styleJs from "../../../utils/style.js";
import utilsJs, {
  getYearFormat,
  getMonthFormat,
  getDateFormat,
  getDatetimeFormat,
} from "../../../utils/utils.js";

export default {
  data() {
    return {
      //打印开始
      printFrom: {
        name1: "",
      },
      printVisiable: false,
      //打印结束
      searchForm: {
        key: "",
      },
      sessionTable: "", //登录账户所在表名
      role: "", //权限
      userId: "", //当前登录人的id
      //级联表下拉框搜索条件
      //当前表下拉框搜索条件
      xiqukepuTypesSelectSearch: [],
      form: {
        id: null,
        xiqukepuName: null,
        xiqukepuPhoto: null,
        xiqukepuTypes: null,
        insertTime: null,
        xiqukepuContent: null,
        createTime: null,
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      showFlag: true,
      sfshVisiable: false,
      shForm: {},
      chartVisiable: false,
      echartsDate: new Date(), //echarts的时间查询字段
      addOrUpdateFlag: false,
      contents: null,
      layouts: "",

      //导出excel
      json_fields: {
        //级联表字段
        //本表字段
        中医药文化知识科普名称: "xiqukepuName",
        中医药文化知识科普图片: "xiqukepuPhoto",
        中医药文化知识科普类型: "xiqukepuValue",
        中医药文化知识科普发布时间: "insertTime",
      },
    };
  },
  created() {
    this.contents = styleJs.listStyle();
    this.init();
    this.getDataList();
    this.contentStyleChange();
  },
  mounted() {
    //获取当前登录用户的信息
    this.sessionTable = this.$storage.get("sessionTable");
    this.role = this.$storage.get("role");
    this.userId = this.$storage.get("userId");
  },
  filters: {
    htmlfilter: function (val) {
      return val.replace(/<[^>]*>/g).replace(/undefined/g, "");
    },
  },
  components: {
    AddOrUpdate,
  },
  computed: {
    getActionUrl: function () {
      return `/` + this.$base.name + `/file/upload`;
    },
  },
  methods: {
    chartDialog() {
      let _this = this;
      let params = {
        dateFormat: "%Y", //%Y-%m
        riqi: getYearFormat(_this.echartsDate), //年
        // riqi :getMonthFormat(_this.echartsDate),//年月
        thisTable: {
          //当前表
          tableName: "xiqukepu", //当前表表名,
          sumColum: "xiqukepu_number", //求和字段
          date: "insert_time", //分组日期字段
          // string : 'xiqukepu_name',//分组字符串字段
          // types : 'xiqukepu_types',//分组下拉框字段
        },
        // joinTable : {//级联表（可以不存在）
        //     tableName :'yonghu',//级联表表名
        //     // date : 'insert_time',//分组日期字段
        //     string : 'yonghu_name',//分组字符串字段
        //     // types : 'yonghu_types',//分组下拉框字段
        // }
      };
      _this.chartVisiable = true;
      _this.$nextTick(() => {
        var statistic = this.$echarts.init(
          document.getElementById("statistic"),
          "macarons"
        );
        this.$http({
          url: "barSum", //barCountOne barCountTwo barSumOne barSumTwo
          method: "get",
          params: params,
        }).then(({ data }) => {
          if (data && data.code === 0) {
            let yAxisName = "数值"; //y轴
            let xAxisName = "月份"; //x轴
            let series = []; //具体数据值
            data.data.yAxis.forEach(function (item, index) {
              //点击可关闭的按钮字符串在后台方法中
              let tempMap = {};
              tempMap.name = data.data.legend[index];
              tempMap.type = "bar";
              tempMap.data = item;
              series.push(tempMap);
            });

            var option = {
              tooltip: {
                trigger: "axis",
                axisPointer: {
                  type: "cross",
                  crossStyle: {
                    color: "#999",
                  },
                },
              },
              toolbox: {
                feature: {
                  // dataView: { show: true, readOnly: false },  // 数据查看
                  magicType: { show: true, type: ["line", "bar"] }, //切换图形展示方式
                  // restore: { show: true }, // 刷新
                  saveAsImage: { show: true }, //保存
                },
              },
              legend: {
                data: data.data.legend, //标题  可以点击导致某一列数据消失
              },
              xAxis: [
                {
                  type: "category",
                  axisLabel: { interval: 0 },
                  name: xAxisName,
                  data: data.data.xAxis,
                  axisPointer: {
                    type: "shadow",
                  },
                },
              ],
              yAxis: [
                {
                  type: "value", //不能改
                  name: yAxisName, //y轴单位
                  axisLabel: {
                    formatter: "{value}", // 后缀
                  },
                },
              ],
              series: series, //具体数据
            };
            statistic.setOption(option, true);
            window.onresize = function () {
              statistic.resize();
            };
          } else {
            this.$message({
              message: "报表未查询到数据",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.search();
              },
            });
          }
        });
      });
      ////饼状图
      //_this.chartVisiable = true;
      // this.$nextTick(()=>{
      //     var statistic = this.$echarts.init(document.getElementById("statistic"),'macarons');
      //     let params = {
      //         tableName: "xiqukepu",
      //         groupColumn: "xiqukepu_types",
      //     }
      //     this.$http({
      //         url: "newSelectGroupCount",//pieSum pieCount
      //         method: "get",
      //         params: params
      //     }).then(({data}) => {
      //         if (data && data.code === 0) {
      //             let res = data.data;
      //             let xAxis = [];
      //             let yAxis = [];
      //             let pArray = []
      //             var option = {};
      //             for(let i=0;i<res.length;i++){
      //                 xAxis.push(res[i].name);
      //                 yAxis.push(res[i].value);
      //                 pArray.push({
      //                     value: res[i].value,
      //                     name: res[i].name
      //                 })
      //                 option = {
      //                     title: {
      //                         text: '保险合同类型统计',
      //                         left: 'center'
      //                     },
      //                     tooltip: {
      //                         trigger: 'item',
      //                         formatter: '{b} : {c} ({d}%)'
      //                     },
      //                     legend: {
      //                         orient: 'vertical',
      //                         left: 'left'
      //                     },
      //                     series: [
      //                         {
      //                             type: 'pie',
      //                             radius: '55%',
      //                             center: ['50%', '60%'],
      //                             data: pArray,
      //                             emphasis: {
      //                                 itemStyle: {
      //                                     shadowBlur: 10,
      //                                     shadowOffsetX: 0,
      //                                     shadowColor: 'rgba(0, 0, 0, 0.5)'
      //                                 }
      //                             }
      //                         }
      //                     ]
      //                 };
      //             }
      //             statistic.setOption(option,true);
      //             window.onresize = function() {
      //                 statistic.resize();
      //             };
      //         }
      //     });
      // })
    },
    contentStyleChange() {
      this.contentSearchStyleChange();
      this.contentBtnAdAllStyleChange();
      this.contentSearchBtnStyleChange();
      this.contentTableBtnStyleChange();
      this.contentPageStyleChange();
    },
    contentSearchStyleChange() {
      this.$nextTick(() => {
        document
          .querySelectorAll(".form-content .slt .el-input__inner")
          .forEach((el) => {
            let textAlign = "left";
            if (this.contents.inputFontPosition == 2) textAlign = "center";
            if (this.contents.inputFontPosition == 3) textAlign = "right";
            el.style.textAlign = textAlign;
            el.style.height = this.contents.inputHeight;
            el.style.lineHeight = this.contents.inputHeight;
            el.style.color = this.contents.inputFontColor;
            el.style.fontSize = this.contents.inputFontSize;
            el.style.borderWidth = this.contents.inputBorderWidth;
            el.style.borderStyle = this.contents.inputBorderStyle;
            el.style.borderColor = this.contents.inputBorderColor;
            el.style.borderRadius = this.contents.inputBorderRadius;
            el.style.backgroundColor = this.contents.inputBgColor;
          });
        if (this.contents.inputTitle) {
          document
            .querySelectorAll(".form-content .slt .el-form-item__label")
            .forEach((el) => {
              el.style.color = this.contents.inputTitleColor;
              el.style.fontSize = this.contents.inputTitleSize;
              el.style.lineHeight = this.contents.inputHeight;
            });
        }
        setTimeout(() => {
          document
            .querySelectorAll(".form-content .slt .el-input__prefix")
            .forEach((el) => {
              el.style.color = this.contents.inputIconColor;
              el.style.lineHeight = this.contents.inputHeight;
            });
          document
            .querySelectorAll(".form-content .slt .el-input__suffix")
            .forEach((el) => {
              el.style.color = this.contents.inputIconColor;
              el.style.lineHeight = this.contents.inputHeight;
            });
          document
            .querySelectorAll(".form-content .slt .el-input__icon")
            .forEach((el) => {
              el.style.lineHeight = this.contents.inputHeight;
            });
        }, 10);
      });
    },
    // 搜索按钮
    contentSearchBtnStyleChange() {
      this.$nextTick(() => {
        document
          .querySelectorAll(".form-content .slt .el-button--success")
          .forEach((el) => {
            el.style.height = this.contents.searchBtnHeight;
            el.style.color = this.contents.searchBtnFontColor;
            el.style.fontSize = this.contents.searchBtnFontSize;
            el.style.borderWidth = this.contents.searchBtnBorderWidth;
            el.style.borderStyle = this.contents.searchBtnBorderStyle;
            el.style.borderColor = this.contents.searchBtnBorderColor;
            el.style.borderRadius = this.contents.searchBtnBorderRadius;
            el.style.backgroundColor = this.contents.searchBtnBgColor;
          });
      });
    },
    // 新增、批量删除
    contentBtnAdAllStyleChange() {
      this.$nextTick(() => {
        document
          .querySelectorAll(".form-content .ad .el-button--success")
          .forEach((el) => {
            el.style.height = this.contents.btnAdAllHeight;
            el.style.color = this.contents.btnAdAllAddFontColor;
            el.style.fontSize = this.contents.btnAdAllFontSize;
            el.style.borderWidth = this.contents.btnAdAllBorderWidth;
            el.style.borderStyle = this.contents.btnAdAllBorderStyle;
            el.style.borderColor = this.contents.btnAdAllBorderColor;
            el.style.borderRadius = this.contents.btnAdAllBorderRadius;
            el.style.backgroundColor = this.contents.btnAdAllAddBgColor;
          });
        document
          .querySelectorAll(".form-content .ad .el-button--danger")
          .forEach((el) => {
            el.style.height = this.contents.btnAdAllHeight;
            el.style.color = this.contents.btnAdAllDelFontColor;
            el.style.fontSize = this.contents.btnAdAllFontSize;
            el.style.borderWidth = this.contents.btnAdAllBorderWidth;
            el.style.borderStyle = this.contents.btnAdAllBorderStyle;
            el.style.borderColor = this.contents.btnAdAllBorderColor;
            el.style.borderRadius = this.contents.btnAdAllBorderRadius;
            el.style.backgroundColor = this.contents.btnAdAllDelBgColor;
          });
        document
          .querySelectorAll(".form-content .ad .el-button--warning")
          .forEach((el) => {
            el.style.height = this.contents.btnAdAllHeight;
            el.style.color = this.contents.btnAdAllWarnFontColor;
            el.style.fontSize = this.contents.btnAdAllFontSize;
            el.style.borderWidth = this.contents.btnAdAllBorderWidth;
            el.style.borderStyle = this.contents.btnAdAllBorderStyle;
            el.style.borderColor = this.contents.btnAdAllBorderColor;
            el.style.borderRadius = this.contents.btnAdAllBorderRadius;
            el.style.backgroundColor = this.contents.btnAdAllWarnBgColor;
          });
      });
    },
    // 表格
    rowStyle({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        if (this.contents.tableStripe) {
          return { color: this.contents.tableStripeFontColor };
        }
      } else {
        return "";
      }
    },
    cellStyle({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        if (this.contents.tableStripe) {
          return { backgroundColor: this.contents.tableStripeBgColor };
        }
      } else {
        return "";
      }
    },
    headerRowStyle({ row, rowIndex }) {
      return { color: this.contents.tableHeaderFontColor };
    },
    headerCellStyle({ row, rowIndex }) {
      return { backgroundColor: this.contents.tableHeaderBgColor };
    },
    // 表格按钮
    contentTableBtnStyleChange() {
      // this.$nextTick(()=>{
      //   setTimeout(()=>{
      //     document.querySelectorAll('.table-content .tables .el-table__body .el-button--success').forEach(el=>{
      //       el.style.height = this.contents.tableBtnHeight
      //       el.style.color = this.contents.tableBtnDetailFontColor
      //       el.style.fontSize = this.contents.tableBtnFontSize
      //       el.style.borderWidth = this.contents.tableBtnBorderWidth
      //       el.style.borderStyle = this.contents.tableBtnBorderStyle
      //       el.style.borderColor = this.contents.tableBtnBorderColor
      //       el.style.borderRadius = this.contents.tableBtnBorderRadius
      //       el.style.backgroundColor = this.contents.tableBtnDetailBgColor
      //     })
      //     document.querySelectorAll('.table-content .tables .el-table__body .el-button--primary').forEach(el=>{
      //       el.style.height = this.contents.tableBtnHeight
      //       el.style.color = this.contents.tableBtnEditFontColor
      //       el.style.fontSize = this.contents.tableBtnFontSize
      //       el.style.borderWidth = this.contents.tableBtnBorderWidth
      //       el.style.borderStyle = this.contents.tableBtnBorderStyle
      //       el.style.borderColor = this.contents.tableBtnBorderColor
      //       el.style.borderRadius = this.contents.tableBtnBorderRadius
      //       el.style.backgroundColor = this.contents.tableBtnEditBgColor
      //     })
      //     document.querySelectorAll('.table-content .tables .el-table__body .el-button--danger').forEach(el=>{
      //       el.style.height = this.contents.tableBtnHeight
      //       el.style.color = this.contents.tableBtnDelFontColor
      //       el.style.fontSize = this.contents.tableBtnFontSize
      //       el.style.borderWidth = this.contents.tableBtnBorderWidth
      //       el.style.borderStyle = this.contents.tableBtnBorderStyle
      //       el.style.borderColor = this.contents.tableBtnBorderColor
      //       el.style.borderRadius = this.contents.tableBtnBorderRadius
      //       el.style.backgroundColor = this.contents.tableBtnDelBgColor
      //     })
      //   }, 50)
      // })
    },
    // 分页
    contentPageStyleChange() {
      let arr = [];
      if (this.contents.pageTotal) arr.push("total");
      if (this.contents.pageSizes) arr.push("sizes");
      if (this.contents.pagePrevNext) {
        arr.push("prev");
        if (this.contents.pagePager) arr.push("pager");
        arr.push("next");
      }
      if (this.contents.pageJumper) arr.push("jumper");
      this.layouts = arr.join();
      this.contents.pageEachNum = 10;
    },

    init() {},
    search() {
      this.pageIndex = 1;
      this.getDataList();
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let params = {
        page: this.pageIndex,
        limit: this.pageSize,
        sort: "id",
      };

      if (
        this.searchForm.xiqukepuName != "" &&
        this.searchForm.xiqukepuName != undefined
      ) {
        params["xiqukepuName"] = "%" + this.searchForm.xiqukepuName + "%";
      }

      if (
        this.searchForm.xiqukepuTypes != "" &&
        this.searchForm.xiqukepuTypes != undefined
      ) {
        params["xiqukepuTypes"] = this.searchForm.xiqukepuTypes;
      }

      params["xiqukepuDelete"] = 1; // 逻辑删除字段 1 未删除 2 删除

      this.$http({
        url: "xiqukepu/page",
        method: "get",
        params: params,
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });

      //查询级联表搜索条件所有列表
      //查询当前表搜索条件所有列表
      //填充下拉框选项
      this.$http({
        url: "dictionary/page?dicCode=xiqukepu_types&page=1&limit=100",
        method: "get",
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.xiqukepuTypesSelectSearch = data.data.list;
        }
      });
    },
    //每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandler(val) {
      this.dataListSelections = val;
    },
    // 添加/修改
    addOrUpdateHandler(id, type) {

      this.addOrUpdateFlag = true;
      this.crossAddOrUpdateFlag = false;
      this.showFlag = false;
      if (type != "info") {
        type = "else";
      }
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id, type);
      });
    },
    // 下载
    download(file) {
      window.open(" ${file} ");
    },
    // 弹出打印模态框
    dayinOpen(item) {
      let _this = this;
      _this.printVisiable = true;
      _this.printFrom = item;
    },
    // 打印内容
    printContent() {
      let _this = this;
      _this.$print(_this.$refs.printContent);
      _this.printVisiable = false;
    },
    // 删除
    deleteHandler(id) {
      var ids = id
        ? [Number(id)]
        : this.dataListSelections.map((item) => {
            return Number(item.id);
          });

      this.$confirm(`确定进行[${id ? "删除" : "批量删除"}]操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$http({
          url: "xiqukepu/delete",
          method: "post",
          data: ids,
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.search();
              },
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    },
    // 导入功能上传文件成功后调用导入方法
    xiqukepuUploadSuccess(data) {
      let _this = this;
      _this
        .$http({
          url: "xiqukepu/batchInsert?fileName=" + data.file,
          method: "get",
        })
        .then(({ data }) => {
          if (data && data.code === 0) {
            _this.$message({
              message: "导入中医药文化知识科普数据成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                _this.search();
              },
            });
          } else {
            _this.$message.error(data.msg);
          }
        });
    },
    // 导入功能上传文件失败后调用导入方法
    xiqukepuUploadError(data) {
      this.$message.error("上传失败");
    },
    formatHerbalTime(time) {
      return dayjs(time).format("甲子年MM月DD日 HH:mm");
    },
    handleImagePreview(row) {
      this.$imagePreview({
        images: [this.$base.url + row.xiqukepuPhoto],
        closeOnPressEscape: true,
        showToolbar: false,
        customClass: "herbal-preview",
      });
    },
    //无用
    wuyong(id) {
      let _this = this;
      _this
        .$confirm(`确定    操作?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
        .then(() => {
          _this
            .$http({
              url: "xiqukepu/update",
              method: "post",
              data: {
                id: id,
                //                            xiqukepuTypes:xiqukepuTypes,
              },
            })
            .then(({ data }) => {
              if (data && data.code === 0) {
                _this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    _this.search();
                  },
                });
              } else {
                _this.$message.error(data.msg);
              }
            });
        });
    },
  },
};
</script>
<style scoped>

.modern-container {
  --primary-color: #409eff;
  --success-color: #67c23a;
  --warning-color: #e6a23c;
  --danger-color: #f56c6c;
  --text-primary: #303133;
  --text-regular: #606266;
  --border-color: #ebeef5;
  --background-base: #f5f7fa;
  --radius-md: 8px;
  --shadow-md: 0 3px 12px rgba(0, 0, 0, 0.08);
}

.modern-search-form {
  background: rgba(255, 255, 255, 0.96);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}
.modern-data-table::v-deep {
  --el-table-header-background-color: rgba(245, 247, 250, 0.9);
  --el-table-border-color: var(--border-color);
  /* color: 333; */
}
.search-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.modern-input::v-deep .el-input__inner,
.modern-select::v-deep .el-input__inner {
  height: 40px;
  border-radius: 20px;
  padding-left: 40px;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}
.modern-search-panel {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}
.search-group {
  display: flex;
  justify-content: center;
  gap: 16px;
  align-items: center;
  width: 90vw;
}
.action-group {
  width: 90vw;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.action-toolbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
}
.modern-input {
  width: 250px;
}
.modern-input::v-deep .el-input__inner {
  border-radius: 20px;
  /* padding-left: 15px; */
}
.modern-date::v-deep .el-input__inner {
  border-radius: 20px;
}

.action-buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.modern-search-btn {
  width: 128px;
  height: 40px;
  padding: 12px 28px;
  border-radius: 20px;
  font-weight: 500;
}

.modern-table-container {
  background: rgba(255, 255, 255, 0.96);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.modern-data-table::v-deep {
  --el-table-header-background-color: rgba(245, 247, 250, 0.9);
  --el-table-border-color: var(--border-color);
}

.modern-data-table::v-deep tr:hover {
  transform: translateX(4px);
  background: rgba(64, 158, 255, 0.03);
  box-shadow: 4px 0 12px rgba(64, 158, 255, 0.05);
}

.modern-card {
  display: flex;
  align-items: center;
  padding: 12px;
  background: rgba(245, 247, 250, 0.3);
  border-radius: 12px;
}

.card-image {
  position: relative;
  margin-right: 16px;
}

.card-image img {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  object-fit: cover;
}

.card-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--warning-color);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
}

.card-content {
  flex: 1;
}

.card-title {
  margin: 0 0 8px;
  color: var(--text-primary);
  font-size: 16px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-type {
  border-radius: 12px;
}

.card-time {
  font-size: 12px;
  color: var(--text-regular);
}

.table-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.action-btn {
  font-size: 18px;
  color: var(--text-regular);
  transition: all 0.2s ease;
}

.action-btn.danger {
  color: var(--danger-color);
}

.action-btn:hover {
  transform: scale(1.1);
  color: var(--primary-color);
}

.modern-pagination {
  padding: 20px;
  display: flex;
  justify-content: flex-end;
  background: rgba(255, 255, 255, 0.9);
}

@media (max-width: 768px) {
  .modern-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .card-image {
    margin-right: 0;
    margin-bottom: 12px;
  }

  .search-fields {
    grid-template-columns: 1fr;
  }
}
</style>
